<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="美团店铺" prop="poiname">
        <el-input
          v-model="queryParams.poiname"
          placeholder="请输入美团店铺名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="ordertypename">
        <el-input
          v-model="queryParams.ordertypename"
          placeholder="请输入美团订单类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务日期" >
        <el-date-picker v-model="queryParams.bizTimeStart" size="small" type="date" value-format="yyyy-MM-dd" placeholder="请选择开始时间" /> -
        <el-date-picker v-model="queryParams.bizTimeEnd" size="small" type="date" value-format="yyyy-MM-dd" placeholder="请选择结束时间"/>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mt:sales:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="salesList" >
      <el-table-column label="订单编号" align="center" prop="code" width="100"/>
      <el-table-column label="美团店铺" align="center" prop="poiname" />
      <el-table-column label="订单类型" align="center" prop="ordertypename" width="80"/>
      <el-table-column label="业务日期" align="center" prop="biztime" width="137">
        <template slot-scope="scope">
          <span>{{parseTime(scope.row.biztime)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="菜品" align="center" prop="dishname" />
      <el-table-column label="SKUid" align="center" prop="skuid" width="85"/>
      <el-table-column label="销售数量" align="center" prop="dishsalecnt" width="60">
        <template slot-scope="scope">
          <span>{{scope.row.dishsalecnt}}{{scope.row.dishunitname}}</span>
        </template>
      </el-table-column>
      <el-table-column label="菜品原价" align="center" prop="dishsaleamt" width="80">
        <template slot-scope="scope">
          <span>{{scope.row.dishsaleamt}}元</span>
        </template>
      </el-table-column>
      <el-table-column label="菜品优惠" align="center" prop="dishcmpgnamt" width="60">
        <template slot-scope="scope">
          <span>{{scope.row.dishcmpgnamt}}元</span>
        </template>
      </el-table-column>
      <el-table-column label="菜品收入" align="center" prop="dishincomeamt" width="80">
        <template slot-scope="scope">
          <span>{{scope.row.dishincomeamt}}元</span>
        </template>
      </el-table-column>
      <el-table-column label="税额" align="center" prop="taxamt" width="60"/>
      <el-table-column label="不含税收入" align="center" prop="notaxincomeamt" width="80">
        <template slot-scope="scope">
          <span>{{scope.row.notaxincomeamt}}元</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" width="160">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="60">
        <template slot-scope="scope">
          <el-button type="text" size="mini" icon="el-icon-info" @click="getSaleInfo(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listSales, getSales, delSales, addSales, updateSales, exportSales } from "@/api/mt/sales";
import {listSalesItem} from '@/api/mt/salesItem'

export default {
  name: "mtSales",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      loading1:true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 美团门店菜品销售主表格数据
      salesList: [],
      //菜品销售详情列表
      salesItemList:[],
      saleStatus:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mtShopid: null,
        poiname: null,
        merchantno: null,
        ordertypename: null,
        dishcatename: null,
        secondcatename: null,
        code: null,
        biztime: null,
        dishid: null,
        skuid: null,
        customerid: null,
        customername: null,
        deptId: null,
        deptName: null,
        productguid: null,
        productname: null,
        spguid: null,
        bizTimeStart:null,
        bizTimeEnd:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("mt_sales_status").then(response=>{
      this.saleStatus=response.data;
    })
  },
  methods: {
    saleStat(row,column){
      return this.selectDictLabel(this.saleStatus,row.status)
    },
    getSaleInfo(id){
      this.$router.push({path:"/mt/mtSalesItem",query:{id:id}})
    },
    /** 查询美团门店菜品销售主列表 */
    getList() {
      this.loading = true;
      listSales(this.queryParams).then(response => {
        this.salesList = response.rows;
        this.total = response.total;
        this.form=this.salesList[0];
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mtShopid: null,
        mtOrgid: null,
        orgId: null,
        orgName: null,
        poiname: null,
        merchantno: null,
        ordertypename: null,
        dishcatename: null,
        secondcatename: null,
        code: null,
        biztime: null,
        dishid: null,
        skuid: null,
        dishname: null,
        dishspec: null,
        dishunitname: null,
        dishsalecnt: null,
        dishsaleamt: null,
        dishcmpgnamt: null,
        dishincomeamt: null,
        taxamt: null,
        notaxincomeamt: null,
        customerid: null,
        customername: null,
        deptId: null,
        deptName: null,
        storeroomguid: null,
        storeroomname: null,
        storehouseguid: null,
        storehousename: null,
        productguid: null,
        productname: null,
        spguid: null,
        spname: null,
        erpWeight: null,
        stockunitid: null,
        stockunitname: null,
        erpPrice: null,
        status: 0,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有美团门店菜品销售主数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSales(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
